<?php
require 'page.class.php';
session_start();

$username=$_SESSION['username'];
$connetc=mysql_connect("localhost","root","");
mysql_select_db("shenji",$connetc);
mysql_query("set names utf8");
$sql4="select * from user where username='$username'";

$result4=mysql_query($sql4);
$row4=mysql_num_rows($result4);


if($row4==0){
	echo "<script>alert('用户不存在，请重新登录！');top.location.href='./login.php'</script>";
}else{


$sql2="select count(*) as amount from jiekou";
$result2=mysql_query($sql2);
$row2=mysql_fetch_array($result2);
$count=$row2['amount'];//总条数
$pagesize=10;//每页显示的条数
if($count%$pagesize){
	$page=ceil($count/$pagesize);
}else{
	$page=$count/$pagesize;
}
if(isset($_GET['currentpage'])){
	$currentpage=intval($_GET['currentpage']);
}else{
	$currentpage=1;
}
$start=($currentpage-1)*$pagesize;

$sql="select * from jiekou left join type on jiekou.typeid=type.typeid order by id desc limit $start,$pagesize";
$result = mysql_query($sql);
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/colResizable-1.6.min.js"></script>
<style>
      .tip{
		  width:600px;
		  height:400px;
	  }

</style>
<script type="text/javascript">
$(function(){
  $("table").colResizable();
});
$(document).ready(function(){
  $(".click").click(function(){
     $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
     $(".tip").fadeOut(200);
  });
});

   function shouzhong_name(){
	    var licesneid=$("#licesneid").val();
		  if(licesneid==null||licesneid.length==0){
			  $("#yz_name").show();
			  
		  }else{
			  $("#yz_name").hide();
		  }
		
   }
   

 $(document).ready(function(){
	  
	  var username="<?php echo $_SESSION['username']; ?>";
	  if(username==null||username.length==0){		  
		 window.top.location.href="../login.php";
	  }
	  
  })	   
</script>

</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">接口配置</a></li>
    <li><a href="#">机器码列表</a></li>
    </ul>
    </div>
	
    <div class="rightinfo">
    
    <div class="tools">
    	<ul class="toolbar">
        <li><a href="insert_jiekou.php"><span><img src="images/t01.png" /></span>添加</a></li>
        <li onclick="deletebatch()"><span><img src="images/t03.png"/></span>删除</li>
        <li style="border:none;">
        <form method="post" action="download1.php">		
        <select name="typeid" style="width:86px;height:34px;border:1px solid #ccc;">
		<?php $downsql="select * from type"; $downresult=mysql_query($downsql); while($downrow=mysql_fetch_assoc($downresult)){?>
			<option value="<?php echo $downrow['typeid'] ?>"><?php echo $downrow['name'] ?></option>
		<?php } ?>
		</select>
		<input style="border:1px solid #ccc;padding:6px 10px;border-radius:5px;" name="downsub" type="submit"value="下载">
		</form>
		</li>
        </ul>
    </div>
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th style="width:3%;"><input  type="checkbox" name="checkbox" onclick="selectAll(this)"/></th>
        <th style="width:20%;">licesneid</th>
        <th style="width:20%;">备注</th>
        <th style="width:5%;">类型</th>
        <th style="width:12.5%;">基本操作</th>
        </tr>
        </thead>
        <tbody>
		<?php
		while($row=mysql_fetch_array($result)){
		?>
		<tr>
        <td><input  type="checkbox" name="son_checkbox" value="<?php echo $row['id'];?>"/></td>
        <td><?php echo $row['licesneid'];?></a></td>
        <td><?php echo $row['beizhu'];?></td>
        <td><?php echo $row['name']?></td>
		<?php
		    if($row['status']==1){
				$kg="<a href='#' onclick='kq(".$row['id'].",1)'>开启</a>";
			}else{
				$kg="<a href='#' onclick='kq(".$row['id'].",0)'>关闭</a>";
			}
		
		?>
        <td><a  onclick="ck('<?php echo $row['id'];?>');" class="tablelink" href="#"><?php echo $kg;?></a>&nbsp;&nbsp;&nbsp;&nbsp;<a  onclick="ck('<?php echo $row['id'];?>');" class="tablelink" href="#">修改</a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="delete_jiekou.php?id=<?php echo $row['id'];?>"onclick="if(confirm('确认删除？')==false)return false;" class="tablelink"> 删除</a></td>
        </tr> 
		<?php
	     }	
		?>
        </tbody>
    </table>
	
    <div class="pagin">
    	<?php 
    		pagelinks();
    	?>
    </div>
	
    <div class="tip">
	  <div class="tiptop"><span>机器码栏目</span><a id="refresh"></a></div>
      <div class="formbody">
      <form method="post" action="update_jiekou.php">
	  <input size="20" type="hidden" name="id" id="id">
      <ul class="forminfo">
      <li><label>机器码</label><input  id="licesneid" name="licesneid" type="text" onblur="shouzhong_name();" class="dfinput" /><i id="yz_name" style="display:none;color:#f00;">机器码由中文、字母、数字组成！</i></li>
	  <li><label>备注</label><textarea id="beizhu" name="beizhu" style="width:325px;height:150px;" onblur="shouzhong_beizhu();" class="textinput"></textarea><i id="yz_beizhu" style="display:none;color:#f00;">备注由中文、字母、数字组成！</i></li>
	  <li>
		<label>类型</label>
		<select id="opt" name="typeid" style="width:86px;height:34px;border:1px solid #ccc;">
		<?php $sql="select * from type"; $result=mysql_query($sql); while($rows=mysql_fetch_assoc($result)){?>
			<option  value="<?php echo $rows['typeid'] ?>"><?php echo $rows['name'] ?></option>
		<?php } ?>
		</select>
	</li>
      <li><label>&nbsp;</label><input name="submit" type="submit" class="btn" value="确认保存" /></li>
      </ul>
	  </form>
      </div>
      <!--
	  <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" />&nbsp;
      <input name="" type="button"  class="cancel" value="取消" />
      </div>
	  -->
    </div>
	
    </div>
    
    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	function ck(id){
			$.post("select_jiekou_id.php",{id:id},function(data){
				   $("#id").val(data['id']);
				   $("#licesneid").val(data['licesneid']);
				   $("#beizhu").val(data['beizhu']);
				   $("#opt").val(data['typeid']);
				   var c=data['typeid'];
				   $("#opt option[value='c']").attr("selected",true)
				   //var checkText=$("#opt option[value='']").find("option:selected").text(); 
				   //alert(checkText);
				   $(".tip").fadeIn(200);
			},"json")	
	}
	function selectAll(objs){
	    obj=document.getElementsByName('son_checkbox');
		for(var i=0;i<obj.length;i++){
			if(objs.checked){
				obj[i].checked=true;
			}else{
				obj[i].checked=false;
			}
			
		}
	}
	
	function deletebatch(){
	      obj=document.getElementsByName('son_checkbox');
		  var arrayid=new Array();
		  for(var i=0;i<obj.length;i++){
			  if(obj[i].checked){
				 var value=obj[i].value;
				 arrayid.push(value);
			  }
			  
		  }
		  
		  if(arrayid.length==0){
			  alert("请选择需要删除的任务");
		  }else{
			  
			  if(confirm("确定要删除所选择的机器码吗")){
				  
				  $.post('delete_jiekou.php',{arrayid:arrayid},function(data){
				  window.location.href="select_jiekou.php";
			    });
				  
			  }else{
				  return false;
			  }
			  
		  }
		  
	}

	  
	  
	   function shouzhong_name(){
		   
		  var licesneid=$("#licesneid").val();
		  if(licesneid==null||licesneid.length==0){
			  $("#yz_name").show();
			  
		  }else{
			  $("#yz_name").hide();
		  }
		  
     }
	 
    function shouzhong_beizhu(){
		
	  var beizhu=$("#beizhu").val();
	  if(beizhu==null||beizhu.length==0){
		  $("#yz_beizhu").show();
		  
	  }else{
		  $("#yz_beizhu").hide();
	  }
   }
   	$(function(){
		$('.btn').bind('click',function(event){
		var licesneid=/[\u4e00-\u9fa5a-zA-Z0-9\n\r]{3,32}$/;

			if(licesneid.test($('#licesneid').val())){
				$("#yz_name").hide();

			}else{
				$("#yz_name").show();
		
				return false;
			}			
		})
	})
   	$(function(){
		$('.btn').bind('click',function(event){

		var beizhu=/[\u4e00-\u9fa5a-zA-Z0-9\n\r]{3,32}$/;
			if(beizhu.test($('#beizhu').val())){

				$("#yz_beizhu").hide();
			}else{

				$("#yz_beizhu").show();
				return false;
			}			
		})
	})
	$(function(){
		$("#refresh").click(function(){
			location.reload();
		})
	})
	 function kq(id,status){
	
		$.post("change_jiekou.php",{id:id,status:status},function(data){
				   window.location.reload();
		})
     }
	</script>

</body>

</html>
